#include "SDLText.h"
using namespace std;

SDLText::SDLText(const SDLText& source)
	:SDLSprite(source)
{
	mContent = source.mContent;
	mFontColor = source.mFontColor;
	mFontPath = source.mFontPath;
	mFontSize = source.mFontSize;
	mRenderMethod = source.mRenderMethod;
}
SDLText::SDLText(string content, string fontPath)
	:SDLSprite(0)
	,mContent(content)
	,mFontColor(new SDL_Color)
	,mFontPath(fontPath)
	,mFontSize(20)
	,mRenderMethod(TextManager::SOLID)
{
	TextManager::GetInstance()->LoadFont(mFontPath, mFontSize);
	UpdateText();
}
SDLText::SDLText(string content, string fontPath, int size)
	:SDLSprite(0)
	,mContent(content)
	,mFontColor(new SDL_Color)
	,mFontPath(fontPath)
	,mFontSize(size)
	,mRenderMethod(TextManager::SOLID)
{
	TextManager::GetInstance()->LoadFont(mFontPath, mFontSize);
	UpdateText();
}

SDLText::SDLText(const std::string& _content, const std::string& _fontPath, int _size, SDLScene* _scene)
	: SDLSprite(0, _scene), mContent(_content), mFontColor(new SDL_Color), mFontPath(_fontPath), mFontSize(_size), mRenderMethod(TextManager::SOLID)
{
	TextManager::GetInstance()->LoadFont(mFontPath, mFontSize);
	UpdateText();
}

SDLText::SDLText(string content, string fontPath, int size, int renderMethod)
	:SDLSprite(0)
	,mContent(content)
	,mFontColor(new SDL_Color)
	,mFontPath(fontPath)
	,mFontSize(size)
	,mRenderMethod(renderMethod)
{
	TextManager::GetInstance()->LoadFont(mFontPath, mFontSize);
	UpdateText();
}

SDLText::~SDLText()
{
	delete mFontColor;
	mFontColor = 0;
}

void SDLText::SetContent(string str)
{
	mContent = str;
	UpdateText();
}
void SDLText::SetRenderMethod(int renderMethod)
{
	mRenderMethod = renderMethod;
	UpdateText();
}
void SDLText::SetTextColor(int r, int g, int b)
{
	mFontColor->r = r;
	mFontColor->g = g;
	mFontColor->b = b;
	UpdateText();
}
void SDLText::SetTextColor(SDL_Color* color)
{
	mFontColor = color;
	UpdateText();
}
void SDLText::SetTextFont(string fontPath)
{
	mFontPath = fontPath;
	UpdateText();
}
void SDLText::SetTextSize(int size)
{
	mFontSize = size;
	UpdateText();
}

void SDLText::UpdateText()
{
	TextManager::GetInstance()->LoadFont(mFontPath, mFontSize);
	TextManager::GetInstance()->SetFontColor(mFontColor);
	TextManager::GetInstance()->SetRenderMethod(mRenderMethod);
	m_Source = TextManager::GetInstance()->RenderText(mContent);
}